
<template>
  <div class="dashboard-container">
    <div class="app-container">
      <el-card>
        <el-tabs>
          <!-- 放置页签  角色管理-->
          <el-tab-pane label="角色管理">
            <!-- 新增角色按钮 -->
            <el-row style="height:60px">
              <el-button
                icon="el-icon-plus"
                size="small"
                type="primary"
                @click="submit"
              >新增角色</el-button>
            </el-row>
            <!-- 表格 -->
            <el-table :data="list" border="">
              <el-table-column type="index" label="序号" width="120" />
              <el-table-column label="角色名称" prop="name" width="240" />
              <el-table-column label="描述" prop="description" />
              <el-table-column label="操作">
                <template v-slot="{row}">
                  <el-button size="small" type="success">分配权限</el-button>
                  <el-button size="small" type="primary" @click="EditRole(row.id)">编辑</el-button>
                  <el-button size="small" type="danger" @click="delRoleList(row.id)">删除</el-button>
                </template>
              </el-table-column>
            </el-table>
            <!-- 分页组件 -->
            <el-row type="flex" justify="center" align="middle" style="height: 60px">
              <!-- 分页组件 -->
              <el-pagination
                :total="total"
                :page-size="page.pagesize"
                layout="prev,pager,next"
                @current-change="changePage"
              />
            </el-row>
          </el-tab-pane>
          <!-- 公司信息 -->
          <el-tab-pane label="公司信息">
            <el-alert
              title="对公司名称、公司地址、营业执照、公司地区的更新，将使得公司资料被重新审核，请谨慎修改"
              type="info"
              show-icon
              :closable="false"
            />
            <el-form :model="formDate" label-width="120px" style="margin-top:50px">
              <el-form-item label="公司名称" prop="name">
                <el-input v-model="formDate.name " disabled style="width:400px" />
              </el-form-item>
              <el-form-item label="公司地址" prop="companyAddress">
                <el-input v-model="formDate.companyAddress" disabled style="width:400px" />
              </el-form-item>
              <el-form-item label="邮箱" prop="mailbox">
                <el-input v-model="formDate.mailbox" disabled style="width:400px" />
              </el-form-item>
              <el-form-item label="备注" prop=" remarks">
                <el-input v-model="formDate.remarks" type="textarea" :rows="3" disabled style="width:400px" />
              </el-form-item>
            </el-form>
          </el-tab-pane>

        </el-tabs>
      </el-card>
    </div>
    <!-- 编辑新增弹框 -->
    <add-set :visible="showDialog" :role-form="info" />

  </div>
</template>

<script>
import { getRoleList, getCompanyInfo, deleteRole, getRoleDetail } from '@/api/setting'
import { mapGetters } from 'vuex'

import AddSet from './component/add-set.vue'
export default {
  components: { AddSet },
  data() {
    return {
      list: [],
      page: {
        page: 1, // 页数
        pagesize: 2 // 每页条数

      },
      total: 0, // 总条数
      formDate: {},
      showDialog: false,
      info: {}
    }
  },
  computed: {
    ...mapGetters(['companyId'])
  },
  created() {
    this.getRoleList()
    this.getCompanyInfo()
  },

  methods: {
    // 新增角色
    async submit() {
      this.showDialog = true
    },
    // 关闭弹框
    handelClose() {
      this.showDialog = false
    },
    // 编辑列表角色  先回显 再更新
    async EditRole(id) {
      this.showDialog = true
      this.info = await getRoleDetail(id)
    },
    // 删除列表角色
    async  delRoleList(id) {
      await this.$confirm('确定删除吗？')
      await deleteRole(id)
      if (this.list.length === 1 && this.page.page > 1) {
        this.page.page--
      }
      this.getRoleList()
      this.$message.success('删除成功')
    },
    // 获取公司详情
    async getCompanyInfo() {
      this.formDate = await getCompanyInfo(this.companyId)
    },
    // 获取列表角色
    async  getRoleList() {
      const { total, rows } = await getRoleList(this.page)
      // console.log(rows)
      this.total = total
      this.list = rows
    },
    // 修改页码
    changePage(page) {
      this.page.page = page
      this.getRoleList()
    }
    // 打开分配权限

  }
}
</script>

<style>

</style>
